package eu.common.toolkits;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;


/**
 * 获取当前类的根路径
 * 
 * @author 吴振振
 * 
 */
public class ResourceUtil {
	
	public static String root ;

	static{
		try {
			root = URLDecoder.decode(ResourceUtil.class.getResource("/").getPath(),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	public static String getResourceBase(Class<?> clazz) {
		try {
			return URLDecoder.decode(clazz.getResource("").getPath(),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static String getResourcePath(Class<?> clazz, String path) {
		return getResourceBase(clazz) + path;
	}
	
	public static String getResourcePath(String path) {
		return root + path;
	}
	
}
